<template>
	<view class="content">
		<u-form-item v-if="type == 'Nickname'" :label-position="labelPosition" label="昵称" prop="intro">
			<u-input type="input" :border="true" placeholder="请填写昵称" v-model="content" />
		</u-form-item>
		<u-form-item v-if="type == 'introduce'" :label-position="labelPosition" label="简介" prop="intro">
			<u-input type="textarea" :border="true" placeholder="请填写简介" v-model="content" />
		</u-form-item>
		<u-button class="btn" @click="submit">确定</u-button>
	</view>
</template>

<script>
import { API$UpdUserinfo } from '../../../../common/API/home.js';
export default {
	props: {
		isShow: {
			type: Boolean,
			default: true
		}
	},
	data() {
		return {
			type: '',
			labelPosition: 'center',
			content: ''
		};
	},
	onLoad(opt) {
		this.type = opt.type;
		uni.setNavigationBarTitle({ title: this.type == 'Nickname' ? '设置昵称' : '填写简介' });
	},
	methods: {
		async submit() {
			this.UpdUserInfo(this.type == 'Nickname' ? { Nickname: this.content } : { introduce: this.content });
		},
		/*********************************************数据处理部分**************************************************************/
		async UpdUserInfo(json) {
			try {
				uni.showLoading({ mask: true,title:"保存中" });
				let res = await API$UpdUserinfo(json);
				if (res.code == 200) {
					this.$pub.setStorageSync('UserInfo', res.data);
					this.$pub.back();
					setTimeout(() => {
						uni.$emit('FreshGetUserInfo');
						this.$pub.Toast('修改成功~');
					}, 1000);
				}
			} catch (e) {
				this.$pub.Toast(e);
			} finally {
				uni.hideLoading();
			}
		}
	}
};
</script>

<style lang="less" scoped>
.content {
	padding: 20rpx;
}
.btn {
	background: rgb(41, 121, 255) !important;
	color: #fff;
}
</style>
